//
//  XDSelCityHotCityTCell.m
//  kabu
//
//  Created by XiangDongMBP on 2017/2/23.
//  Copyright © 2017年 East. All rights reserved.
//

#import "XDSelCityHotCityTCell.h"
#import "XDSelCityHotCityCCell.h"

@interface XDSelCityHotCityTCell()<UICollectionViewDelegate, UICollectionViewDataSource>

@end

static NSString *const kReuseCellId = @"XDSelCityHotCityCCell";

@implementation XDSelCityHotCityTCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.collectionView.scrollEnabled = NO;
    UINib *cellNib = [UINib nibWithNibName:kReuseCellId bundle:nil];
    [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:kReuseCellId];

    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.cityArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    XDSelCityHotCityCCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kReuseCellId forIndexPath:indexPath];
    cell.titleLabel.text = self.cityArray[indexPath.item];
    return cell;
}

#pragma mark - <UICollectionViewDelegateFlowLayout>
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat width = (CGRectGetWidth(self.contentView.bounds) - 2*15.0 - 2 * 10.0) / 3.0;
    return CGSizeMake(width, 38.0);
}

#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.delegate respondsToSelector:@selector(xDSelCityHotCityTCell:selectIndex:)]) {
        [self.delegate xDSelCityHotCityTCell:self selectIndex:indexPath.item];
    }
}



- (void)setCityArray:(NSArray<NSString *> *)cityArray {
    _cityArray = cityArray;
    
    [self.collectionView reloadData];
}

@end
